package tjs.study.notes.dotest.jdk.thread;

/**
 * Created by Nicky.Tang on 2021/11/17 11:21 上午
 *
 * @since 02.12.10
 */
public class DoTestOfJoin {
    public static void main(String[] args) throws InterruptedException {
        Thread  t1 = new Thread(() -> {
            try {
                Thread.currentThread().sleep(1000);
                System.out.println("t1 已启动");
                Thread.currentThread().sleep(2000);
                System.out.println("t1 已结束");
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        Thread  t2 = new Thread(() -> {
            try {
                Thread.currentThread().sleep(1000);
                System.out.println("t2 已启动");
                /**
                 * join 内部调用的也是t1.wait; t1结束后会回调t1.notifyAll
                 * {@link Thread#exit()}
                 * {@link ThreadGroup#threadTerminated(java.lang.Thread)}
                 */
                t1.join();//join方法时synchronized修饰的
//                synchronized (t1){
//                    t1.wait();
//                }
                System.out.println("t2 已结束");
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        t1.start();
        t2.start();
    }
}
